package com.example.user.service;

import com.example.user.dao.UserMapper;
import entity.LoginEntity;
import entity.Rsp;
import entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.JwtUtil;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserMapper userMapper;


    @Override
    public Rsp loginWithUsernameAndPass(LoginEntity loginParam) {


        UserEntity userEntity = userMapper.loginWithUsernameAndPass(loginParam.getUserName(), loginParam.getPassword());

        if(userEntity!=null){
            try {
                return Rsp.success(JwtUtil.createToken(userEntity));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else {
            return Rsp.fail().msg("登录失败：账号或密码错误");
        }


        return null;
    }
}
